<template>
  <el-dialog
    v-el-drag-dialog
    title="合格判定设置"
    :visible.sync="isShow"
    width="500px"
    @closed="reset"
  >
    <el-form
      ref="dataFormRef"
      :rules="rules"
      :model="form"
      label-position="left"
      label-width="100px"
    >
      <el-form-item label="合格判定:" prop="check">
        <el-radio-group v-model="form.check">
          <el-radio :label="1">勾选合格</el-radio>
          <el-radio :label="0">勾选不合格</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button @click="reset"> 关闭 </el-button>
      <el-button :loading="$loadingPlugin.submit" type="primary" @click="save">
        保存
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { fillingcheckQualified } from '@/api'
  export default {
    data() {
      return {
        isShow: false,
        form: {
          ids: '',
          check: 1
        },
        rules: {
          check: [{ required: true, message: '请选择合格判定', trigger: 'change' }]
        }
      }
    },
    methods: {
      show(ids) {
        this.isShow = true
        this.form.ids = ids
      },
      reset() {
        this.$refs['dataFormRef'].resetFields()
        this.isShow = false
      },
      save() {
        this.$refs.dataFormRef.validate((valid) => {
          if (!valid) return
          this.submit()
        })
      },
      async submit() {
        const params = {
          checked: this.form.check,
          detailIds: this.form.ids.join()
        }
        const { status } = await fillingcheckQualified(params)
        if (status === 200) {
          this.$notify({
            title: '提示',
            message: '修改成功',
            type: 'success',
            duration: 2000
          })
          this.reset()
          this.$emit('refresh')
        }
      }
    }
  }
</script>

<style lang="scss" scoped></style>
